<template>
	<view class="intro">
		<view class="font14 title">简介</view>
		<view class="introBox">
			<textarea class="font14" maxlength="50" v-model.trim="introduction" id="" cols="30" rows="10" placeholder="记得填写简介哦" placeholder-class="font14 color666"></textarea>
			<text class="font12 color999">{{introduction.length}}/50</text>
		</view>
		<view class="font12 color999">简介最多只能输入50个字哦~</view>
		<view class="noWidthBtn font14" @click="save">保存</view>
	</view>
</template>

<script>
	import { editGroupInfo,editActivityInfo } from "@/api/send.js"
	import { userName } from "@/utils/verification.js"
	export default {
		data() {
			return {
				introduction:'',
				editId:'',
				from:''
			}
		},
		onLoad(option) {
			let query=JSON.parse(option.query)
			this.introduction=query.intro || ''
			this.editId=query.id || ''
			this.from=query.from || ''
		},
		methods: {
			save(){
				if(!this.introduction){
					uni.showToast({
						icon:'none',
						title:'请填写简介！'
					})
					return
				}else if(this.introduction.length>50){
					uni.showToast({
						icon:'none',
						title:'简介不能超过50个字符！'
					})
					return
				}
				uni.showLoading({
					title:'保存中',
					mask:true
				})
				let param={
					id:this.editId,
					introduction:this.introduction
				}
				if(this.from=='group'){
					editGroupInfo(param).then((res)=>{
						uni.hideLoading()
						if(res.code==100000){
							uni.showToast({
								icon:'none',
								title:'修改成功'
							})
							setTimeout(()=>{
								uni.navigateBack({
									delta:1
								})
							},2000)
						}
					}).catch((err)=>{uni.hideLoading()})
					return
				}else{
					editActivityInfo(param).then((res)=>{
						uni.hideLoading()
						if(res.code==100000){
							uni.showToast({
								icon:'none',
								title:'修改成功'
							})
							setTimeout(()=>{
								uni.navigateBack({
									delta:1
								})
							},2000)
						}
					}).catch((err)=>{uni.hideLoading()})
				}
				
			}
		}
	}
</script>

<style scoped lang="scss">
@import "@/static/public.scss";
.intro{
	padding: 30rpx;
	box-sizing: border-box;
	.title{
		margin: 0 0 30rpx;
	}
	.introBox{
		position: relative;
		textarea{
			width:100%;
			border-radius: 10rpx;
			background:$pageBgColor;
			padding: 10rpx 20rpx;
			box-sizing: border-box;
		}
		text{
			position: absolute;
			right: 20rpx;
			bottom: 10rpx;
		}
	}
	.noWidthBtn{
		width: 200rpx;
		margin: 100rpx auto 0;
	}
}

</style>
